package system;

import java.io.File;
import javax.sound.sampled.*;

public class Sound {
	File sounds;
	Clip clip;
	AudioInputStream ais;
	String name;
	boolean loop;
	boolean mute = false;

	public Sound(String name, boolean loop) {
		this.name = name;
		this.loop = loop;

		try {
			sounds = new File("assets/audio/" + name);
			clip = AudioSystem.getClip();
			AudioInputStream ais = AudioSystem.getAudioInputStream(sounds);
			clip.open(ais);
			//ais.close();

		} catch (Exception e) {
			System.out.println("Failed to play sound");
			e.printStackTrace();
		}
	}

	public void Play(){
		if(clip != null){
			clip.stop();
			clip.setFramePosition(0);
			clip.start();
			if (loop){
				clip.loop(-1);
			} else {
				clip.loop(0);

			}
		}


	}

	public void Stop(){
		if(clip != null) clip.stop();
	}


}
